package com.lagou.service.impl;

import com.lagou.common.CityProvinceConverter;
import com.lagou.common.ServerResponse;
import com.lagou.mapper.CountryMapMapper;
import com.lagou.service.ICountryMapService;
import com.lagou.vo.CityVo;
import com.lagou.vo.ProvinceVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CountryMapServiceImpl implements ICountryMapService {

    @Autowired
    private CountryMapMapper mapper;


    /**获取各个省的招聘人数
     *
     * @return
     */
    @Override
    public ServerResponse<List<ProvinceVo>> getMapData() {

        //查询各个省有哪些城市 没有招聘人数
         List<ProvinceVo> provinceVoList= mapper.queryProvinceCity();

        //查询每个城市招聘人数
        List<CityVo> cityVoList =mapper.queryCityNum();

        //调用转换器的转换方法，传递List<ProvinceVo>  List<CityVo> 得到结果，CityVo中的招聘人数 累加到Province中
        List<ProvinceVo> provinceVos =   CityProvinceConverter.converter(cityVoList,provinceVoList);

        //返回ServerResponse 把List<ProvinceVo> 放进去
        return ServerResponse.createBySuccessData(provinceVos);
    }
}
